import { webSocketService } from "./services/WebSocketService";
import { questionDescriptionWebView } from "./webview/QuestionDescriptionWebView";
import { leetCodeOutputChannel } from "./output/QuestionOutputChannel";
import { commands, ExtensionContext, window } from "vscode";
import { openQuestion } from "./commands/OpenQuestion";
import { testQuestion } from "./commands/TestQuestion";
import { submitQuestion } from "./commands/SubmitQuestion";
import { questionExplorerTreeDataProvider } from "./view/QuestionExplorerTreeDataProvider";
import { questionExplorerTreeItemDecorationProvider } from "./view/QuestionExplorerTreeItemDecorationProvider";
import { languageService } from "./services/LanguageService";
import { Languages } from "./common/Languages";
import { javaServiceProvider } from "./languages/JavaServiceProvider";
import { rustServiceProvider } from "./languages/RustServiceProvider";

export const start = (context: ExtensionContext) => {
    context.subscriptions.push(
        webSocketService,
        questionDescriptionWebView,
        leetCodeOutputChannel,
        commands.registerCommand("leetcode.open.browser", () => webSocketService.openBrowser()),
        commands.registerCommand("leetcode.open.question", (title, titleSlug) => openQuestion(title, titleSlug)),
        commands.registerCommand("leetcode.test.question", (uri) => testQuestion(uri)),
        commands.registerCommand("leetcode.submit.question", (uri) => submitQuestion(uri)),
        commands.registerCommand("leetcode.explorer.refresh", () => questionExplorerTreeDataProvider.refresh()),
        commands.registerCommand("leetcode.explorer.prev", () => questionExplorerTreeDataProvider.prev()),
        commands.registerCommand("leetcode.explorer.next", () => questionExplorerTreeDataProvider.next()),
        window.registerFileDecorationProvider(questionExplorerTreeItemDecorationProvider),
        window.createTreeView("leetcode.question.explorer", {
            canSelectMany: false,
            treeDataProvider: questionExplorerTreeDataProvider
        }),
    );

    webSocketService.start();

    languageService.register(Languages.java, javaServiceProvider);
    languageService.register(Languages.rust, rustServiceProvider);
    languageService.registerContext();
};